/**
 * @FilePath     : \simulations\include\agvWorld\particle.h
 * @Description  : Particle类用于表示粒子在优化算法中的状态，包括粒子的位置、速度、价值等属性，以及一些相关的操作和配置方法。 
 *                 该类还包含了粒子的最佳状态和约束条件的管理，并提供了获取和设置这些属性的方法。 
 * @Author       : xiujun.yang
 * @Version      : 1.0.0
 * @LastEditors  : error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
 * @LastEditTime : 2024-12-19 15:33:27
 * @Copyright (c) 2024 by 临工智能信息科技有限公司, All Rights Reserved. 
**/
#pragma once
#include "z_types.h"

enum ParticleErrorType {
    PARTICLE_NO_ERROR = 0,
    PARTICLE_VARIABLE_NOT_MATCH = 1,
    PARTICLE_VARIABLE_INVALID,
};

class  Particle
{
 public:
    // Class constructor
    Particle (int, const double *, const double *, const double *, double , double , const double *, void (*)(Particle *));
    ~Particle ();

    // Inicialize particle position, velocity, value, bestPosition, bestValue and feasible
    void InitializeParticle ();
    // configure particle position and velocity
    void ConfigureParticle(const double* pos, const double* vel);
    // Update particle position, velocity and value
    void UpdateParticle(const double*);
    // Print particle information
    void PrintParticle() const;
    // Print particle best information
    void PrintParticleBest() const;
    // Get best feasible
    bool GetBestFeasible() const;
    // Get best value
    double GetBestValue() const;
    // Get best position
    const double* GetBestPosition() const;
    // Get position
    const double* GetPosition() const;
    // Get velocity
    double GetValue() const;
    // Get Feasible
    bool GetFeasible() const;
    // Get Error
    int GetError() const;
    
    //设置当前评估位置好坏的量值
    void SetValue(double value);
    // set constraints
    void SetConstraints(double constraints);
    // set feasible
    void SetFeasible(bool feasible);
    // set error
    void SetError(int err);
    // Get number of variables
    static int GetNumberOfVariables();
 private:
    // Update particle best
    void UpdateParticleBest();

    // Particle position
    double* position_;
    // Particle velocity
    double* velocity_;
    // Function value over particle position
    double value_;
    // Particle feasibility
    bool feasible_;
    // Particle best position
    double* best_position_;
    // Function value over particle best position
    double best_value_;
    // best feasible
    bool best_feasible_;
    // Constraints
    double constraints_;
    // Error
    int error_;

 private:
    // Class particle static variables
    static int number_of_variables_;
    // Particle weight
    static const double* weight_;
    // Variables upper bounds
    static const double* upper_bounds_;
    // Variables lower bounds
    static const double* lower_bounds_;
    // Max velocity
    static const double* max_velocity_;
    // Synthony parameters
    static double c1_;
    // Synthony parameters
    static double c2_;
    // Constraint factor
    static double factor_;
    // Pointer to the objective function, returns the feasibility of the particle
    static void (*function_ptr_)(Particle*);
};

